package com.fr;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.StringUtils;

/**
*作者：furong
*日期：2017年5月27日
*时间：下午5:15:42
*/
public class QuerySum {

    public static void main(String[] args) throws IOException {

        String path = "F:\\log_visit_hd_v3_talent(2).json";
        FileReader fr = new FileReader(path);
        BufferedReader br = new BufferedReader(fr);
        Map<String, Integer> map = new HashMap<>();
        String line = null;

        while ((line = br.readLine()) != null) {
            if (line.contains("reqparam")) {
                String[] split = line.split(",");
                for (int i = 0; i < split.length; i++) {
                    String[] a = split[i].split(":");
                    if (a.length >= 2 && StringUtils.isNotBlank(a[1])) {
                        Integer count = map.get(a[0]);
                        if (count == null) {
                            map.put(a[0], 1);
                        } else {
                            count++;
                            map.put(a[0], count);
                        }
                    }

                }
            }
        }
        br.close();
        fr.close();
        List<Entry<String, Integer>> list = new ArrayList<>();
        list.addAll(map.entrySet());
        Collections.sort(list, new Comparator<Entry<String, Integer>>() {

            @Override
            public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {

                return o2.getValue() - o1.getValue();
            }
        });
        for (Entry<String, Integer> e : list) {
            System.out.println(e.getKey() + "\t" + e.getValue());
        }
    }
}
